home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / microcrn / issue_46.arc / 86WRLD46.ARC / 86WORLD.10 next >
Encoding:
Text File  |  1988-05-11  |  4.4 KB  |  126 lines

  1. /* 86WORLD Figure 10 - Font Conversion
  2.    Micro Cornucopia Magazine Issue #46 */
  3.  
  4. /*-- Fill in a Windows Font Header from a Gem Font Header --*/
  5.  
  6. void ConvertG2W( )
  7.   { /* assumes all data is in previously defined global arrays */
  8.   int numchars = (GemFont.gfLastChar - GemFont.gfFirstChar + 1);
  9.  
  10.   /* Translate the header information */
  11.   WinFont.dfVersion = 256;
  12.   strnset(WinFont.dfCopyright,'c',60);
  13.   WinFont.dfType = 0;
  14.   WinFont.dfPoints = GemFont.gfFormHeight;
  15.   WinFont.dfVertRes = 72;
  16.   WinFont.dfHorizRes = 72;
  17.   WinFont.dfAscent = GemFont.gfTopLine;
  18.   if (WinFont.dfAscent == 0)
  19.     WinFont.dfAscent = GemFont.gfAscentLine;
  20.   WinFont.dfInternalLeading = 0;
  21.   WinFont.dfExternalLeading = 0;
  22.   WinFont.dfItalic = 0;
  23.   WinFont.dfUnderline = 0;
  24.   WinFont.dfStrikeOut = 0;
  25.   WinFont.dfWeight = 200;
  26.   WinFont.dfCharSet = 255;
  27.   WinFont.dfPixWidth = 0;
  28.   WinFont.dfPixHeight = GemFont.gfFormHeight;
  29.   WinFont.dfPitchAndFamily = 1; /* low bits indicates proportional */
  30.   WinFont.dfAvgWidth = chofstable['X'+1-GemFont.gfFirstChar]
  31.                        - chofstable['X'-GemFont.gfFirstChar];
  32.   WinFont.dfMaxWidth = MaxWidthInTable(chofstable, numchars);
  33.   WinFont.dfFirstChar = GemFont.gfFirstChar;
  34.   WinFont.dfLastChar = GemFont.gfLastChar;
  35.   WinFont.dfDefaultChar = 0x60 - GemFont.gfFirstChar;
  36.   WinFont.dfBreakChar = 32 - GemFont.gfFirstChar;
  37.   WinFont.dfWidthBytes = GemFont.gfFormWidth;
  38.   WinFont.dfDevice = 0;
  39.   WinFont.dfBitsPointer = 0;
  40.   WinFont.dfBitsOffset = (((sizeof(WinFont) && 1) == 1) ?
  41.                            sizeof(WinFont)+1 : sizeof(WinFont))
  42.                             + ((numchars+1)*2);
  43.   WinFont.dfFace = WinFont.dfBitsOffset
  44.                     + (WinFont.dfWidthBytes * WinFont.dfPixHeight);
  45.   /* NOTE: The following is out of sequence because it depends on
  46.            other computed values in the header */
  47.   strncpy(facename,GemFont.gfName,17);
  48.   facename[16] = 0;
  49.   WinFont.dfSize = WinFont.dfFace + strlen(facename)+1;
  50.   } /* ConvertG2W */
  51.  
  52. /*-- Fill in a Gem Font Header from a Windows Font Header --*/
  53.  
  54. void ConvertW2G( )
  55.   { /* assumes all data is in previously defined global arrays */
  56.   int numchars = (WinFont.dfLastChar - WinFont.dfFirstChar + 1);
  57.  
  58.   /* Translate the header information */
  59.   GemFont.gfID = 2;;
  60.   GemFont.gfPointSize = WinFont.dfPoints;
  61.   strcpy(GemFont.gfName,facename);
  62.   GemFont.gfFirstChar = WinFont.dfFirstChar;
  63.   GemFont.gfLastChar = WinFont.dfLastChar;
  64.   GemFont.gfTopLine = WinFont.dfAscent;
  65.   GemFont.gfAscentLine = WinFont.dfAscent;
  66.   GemFont.gfHalfLine = WinFont.dfAscent/2+1;
  67.   GemFont.gfDescentLine = WinFont.dfPixHeight-WinFont.dfAscent-1;
  68.   GemFont.gfBottomLine = WinFont.dfPixHeight-WinFont.dfAscent;
  69.   GemFont.gfMaxWidth = WinFont.dfMaxWidth;
  70.   GemFont.gfMaxCellWidth = WinFont.dfMaxWidth;
  71.   GemFont.gfLeftOffset = 0;
  72.   GemFont.gfRightOffset = 0;
  73.   GemFont.gfThickening = 1;
  74.   GemFont.gfUndlSize = 1;
  75.   GemFont.gfLightMask = 0x5555;
  76.   GemFont.gfSkewMask = 0x5555;
  77.   GemFont.gfFlags = 0;
  78.   GemFont.gfHorOfsTable = 0;
  79.   GemFont.gfCharOfsTable = ((sizeof(GemFont) && 1) == 1) ?
  80.                            sizeof(GemFont)+1 : sizeof(GemFont);
  81.   GemFont.gfBitsOffset = GemFont.gfCharOfsTable + ((numchars+1)*2);
  82.   GemFont.gfFormWidth  = WinFont.dfWidthBytes;
  83.   GemFont.gfFormHeight = WinFont.dfPixHeight;
  84.   GemFont.gfNextFont = 0;
  85.   if (WinFont.dfPixWidth != 0) /* if fixed pitch in Windows */
  86.     MakeChOfsTable(chofstable, WinFont.dfPixWidth, numchars);
  87.   } /* ConvertW2G */
  88.  
  89. /*-- determine size of a file --*/
  90.  
  91. long fsize(FILE* fp)
  92.   { /* this was written because there is not an ANSI */
  93.     /* standard fsize(). Every compiler has a different one */
  94.     /* This one uses only ANSI routines */
  95.   long tmpsize;
  96.   long pos = ftell(fp);
  97.   fseek(fp, 0L, SEEK_END);
  98.   tmpsize = ftell(fp);
  99.   fseek(fp, pos, SEEK_SET);
  100.   return(tmpsize);
  101.   } /* fsize */
  102.  
  103. /*-- Determine if file is a Windows FNT file --*/
  104.  
  105. int IsWindowsFont(char filename[])
  106.   {
  107.   int temp;
  108.   long size;
  109.  
  110.   FILE* fin = fopen(filename,"rb");
  111.   fread(&temp,2,1,fin);  /* read past version */
  112.   fread(&size,4,1,fin);
  113.   /* read long word in byte 2-5 and see if = length of file */
  114.   temp = (fsize(fin) == size);
  115.   fclose (fin);
  116.   return(temp);
  117.   } /* IsWindowsFont */
  118.  
  119. /*-- Construct a character offset table --*/
  120.  
  121. void MakeChOfsTable(int ChOfsTable[], int Width, int NumChars)
  122.   {
  123.   for (int ct = 0; ct <= NumChars; ct++)
  124.     ChOfsTable[ct] = ct*Width;
  125.   } /* MakeChOfsTable */
  126.